package alo;

import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName test1
 * @Description TODO
 * @Author Fanxc
 * @DATE 2021/4/12 9:38
 * @Version 1.0
 */
public class test3 {

    public int[][] threeOrders (TreeNode root) {
        // write code here
        List<Integer> list1=new LinkedList<>();
        List<Integer> list2=new LinkedList<>();
        List<Integer> list3=new LinkedList<>();
        preorder(root,list1);
        inorder(root,list2);
        postorder(root,list3);
        int [] a=list1.stream().mapToInt(Integer::valueOf).toArray();
        int [] b=list2.stream().mapToInt(Integer::valueOf).toArray();
        int [] c=list3.stream().mapToInt(Integer::valueOf).toArray();
        int[][] res = new int[][]{a,b,c};
        return res;
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
    public void preorder(TreeNode root, List<Integer> list) {
        if (root != null) {
            list.add(root.val);
            preorder(root.left, list);
            preorder(root.right, list);
        }
    }
    public void inorder(TreeNode root, List<Integer> list) {
        if (root != null) {
            inorder(root.left, list);
            list.add(root.val);
            inorder(root.right, list);
        }
    }
    public void postorder(TreeNode root, List<Integer> list) {
        if (root != null) {
            postorder(root.left, list);
            postorder(root.right, list);
            list.add(root.val);
        }
    }
}
